package userLimitService

import (
	"arabApi/app/api/models/userlimitModel"
	"arabApi/app/api/requests/userlimitRequest"
	"github.com/spf13/cast"
	"strings"
)

func UserRoleAdd(r userlimitRequest.UserRoleAdd) bool {
	id := cast.ToInt64(r.UserId)

	ids := strings.Split(r.RoleIds, ",")
	um := make([]userlimitModel.UserRole, len(ids))
	for i, v := range ids {
		u := userlimitModel.UserRole{}
		u.UserId = id
		u.RoleId = cast.ToInt64(v)
		um[i] = u
	}

	userRole := new(userlimitModel.UserRole)
	return userRole.UserRoleAdd(id, um)
}

func UserRole(userId string) []int64 {

	userroles, _ := userlimitModel.UserRole1(cast.ToInt64(userId))
	ids := make([]int64, len(userroles))

	for i, v := range userroles {
		ids[i] = v.RoleId
	}
	return ids
}
